<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Quick Start</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
	<table class="tutorial-nav-box">
	<tr>
		<td style="width: 30%">
							<a href="../psa/tutorial_psa_quick_start.pkg.html"><img src="../media/images/previous_button.png" alt="Previous"></a>
					</td>
		<td style="text-align: center">
					</td>
		<td style="text-align: right; width: 30%">
							<span class="disabled"><img src="../media/images/next_button_disabled.png" alt="Next"></span>
					</td>
	</tr>
	<tr>
		<td style="width: 30%">
							<span class="detail">Quick Start</span>
					</td>
		<td style="text-align: center">
					</td>
		<td style="text-align: right; width: 30%">
					</td>
	</tr>
</table>
	
<div><a name=""></a><div class="ref-title-box"><h1 class="ref-title">Quick Start</h1>
    <h2 class="ref-purpose">This short tutorial will show you how to start using PSA and make a simple application.</h2></div><div class="ref-synopsis"></div> <h1 class="title">Table of Contents</h1>
<ul class="toc">
	
			
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation">Installation</a></li>
					
				  				<ul class="toc">
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.package">Make home directory for your application and get PSA files</a></li>
						
					
				  																				<ul class="toc">
							<li><a href="../psa/tutorial_quick_start.pkg.html#installation.package.download">Download PSA files</a></li>
															
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.package.svn">Checkout from SVN repository</a></li>
					
				  									</ul>
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.database">Create database</a></li>
										
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.config">Change PSA configuration file</a></li>
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.webserver">Configure web server</a></li>
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#installation.bootstrap">Make bootstrap file</a></li>
					
				  															</ul>
						<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1">Make a simple application (Example application 1)</a></li>
																				
					
				  				<ul class="toc">
					<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1.intro">Short introduction</a></li>
						
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1.router">Router</a></li>
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1.controller">Controller</a></li>
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1.model">Model</a></li>
					
					<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp1.view">View</a></li>
					
				  															</ul>
						<li><a href="../psa/tutorial_quick_start.pkg.html#exampleapp2">Not so simple application (Example application 2)</a></li>
																				
					</ul>
 <span><a name="installation"></a><h2 class="title">Installation</h2><span><a name="installation.package"></a><h3 class="title">Make home directory for your application and get PSA files</h3><p>Firstly you will need to create a root directory for your new application that is accessible by your web server. The url to this directory can be, for example, http://localhost/mytestapp. Then you need to get PSA files. You can do that by downloading archive with files or by checkout from SVN repository.</p>
      <a name="installation.package.download"></a><h4 class="title">Download PSA files</h4><p>PSA files can be downloaded from <a href="http://code.google.com/p/phpstartapp/downloads/list">http://code.google.com/p/phpstartapp/downloads/list</a>. Download archive named <em class = "italic">phpstartapp_vXX-revXX-all.zip</em>. It contains all folders and examples used in this document. Archive without 'all' in the name contains only <em class = "italic">psa</em> folder. After download, extract archive content inside your application root directory. After that you should have directory structure like this:</p>
        <pre>mytestapp/
   examples/
   psa/
      plugin_classes/
      scripts/
         ...
   templates/
      smarty/
         cache/
         configs/
         templates_c/</pre>
        <p>Web server must have write permission to directory <em>templates/smarty/templates_c</em> if you will use <a href="http://www.smarty.net/">Smarty</a> template engine. This folder is used for compiled templates. See <a href="http://www.smarty.net/manual/en/">Smarty documentation</a> for details.</p><br />
      <a name="installation.package.svn"></a><h4 class="title">Checkout from SVN repository</h4><p>First create directory named 'psa' for PSA files inside your application root directory and do SVN checkout into it from repository: <em class = "italic">http://phpstartapp.googlecode.com/svn/trunk/psa</em>. After that you need to create folders <em>examples/</em> and <em>templates/</em> with all subfolders as shown above.</p><br /></span>
    <span><a name="installation.database"></a><h3 class="title">Create database</h3><p>You have to create initial database. Name the database as you wish. There are two .sql files with database tables definitions and initial data inside <em class = "italic">install</em> directory if you downloaded PSA archive or you can get them from <a href="http://karmela.fsb.hr/~bmauser/phpstartapp/install/">here</a>. <em class = "italic"><a href="http://phpstartapp.googlecode.com/svn/trunk/install/db_mysql.sql">db_mysql.sql</a></em> is for MySQL database and <em class = "italic"><a href="http://phpstartapp.googlecode.com/svn/trunk/install/db_pgsql.sql">db_pgsql.sql</a></em> is for PostgreSQL database. You will need to have username and password for your database server and some database client to do that. I will not explain this procedure in details; you are probably familiar with that.</p>
      <p>PSA uses <a href="http://www.php.net/pdo">PHP Data Objects (PDO)</a> extension for database access. See <a href="../psa/Psa_Pdo.html">Psa_Pdo</a> class for more details.</p></span>
    <span><a name="installation.config"></a><h3 class="title">Change PSA configuration file</h3><p>Main configuration file is <a href="../psa/_config.php.html">config.php</a> in <em>psa</em> directory. You can set configuration options changing this file, or better, you can make file named <em>config_override.php</em> in the same directory and put options you want to override in it. This way you can easily upgrade PSA especially if you installed from SVN repository. For example your <em>config_override.php</em> can look like this:<div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'pdo'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'dsn'</span><span class="src-sym">]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>=&nbsp;<span class="src-str">&quot;mysql:host=localhost;port=3306;dbname=mydatabase&quot;</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'pdo'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'username'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'databaseUser'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'pdo'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'password'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'databasePass'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'folders'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir_web'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'/mytestapp'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'folders'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'plugins'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'../examples'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'folders'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'smarty'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'template_dir'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-str">'examples/templates/'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p>
      <p>All PSA options you can set in <em><a href="../psa/_config.php.html">config.php</a></em> file are documented in comments. You will surely need to change database connection settings. Add line with web home directory of your application if not at the web server root directory, and add two lines for example applications location and templates.</p></span>
    <span><a name="installation.webserver"></a><h3 class="title">Configure web server</h3><p>I recommend that you configure your web server to rewrite all web requests that do not serve static content like .html or .jpg files to <em>index.php</em> script of your application. That actually depends how you will write router plugin for your application and you will see later that you can write router that do not use rewrite rules, but it's much nicer to use them. So, we want that all requests go through <em>index.php</em> script that should only include <a href="../psa/_front_controller.php.html">front_controller.php</a> script from <em>psa</em> directory. If you use Apache web server make <em>.htaccess</em> file like in the example below in your application root folder (that will be in <em class = "italic">mytestapp</em> folder in folder structure above)<pre>Options +FollowSymLinks

&lt;IfModule mod_rewrite.c&gt;
        RewriteEngine On
       
        # If your web application is not in webserver root folder change RewriteBase directive.
        # If, for example, the url to your application is http://someserver.com/webroot/myapp/
        # uncomment and change this to path where is your index.php script (/webroot/myapp/)
        RewriteBase /mytestapp/
        
        # is a regular file
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        # is a symbolic link
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        # is a directory
        RewriteCond %{REQUEST_FILENAME} -d
        
        # NC - case insensitive, L - last rule
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]        
&lt;/IfModule&gt;</pre></p>
      <p>Note that if your application is not at the web server root folder you should set <em>RewriteBase</em> directive like in this example.</p></span>
    <span><a name="installation.bootstrap"></a><h3 class="title">Make bootstrap file</h3><p>Make <em>index.php</em> script for in your application root folder that only includes <a href="../psa/_front_controller.php.html">front_controller.php</a> script from <em class = "italic">psa</em> directory. <div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-inc">include_once&nbsp;</span><span class="src-str">'psa/front_controller.php'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p></span></span><span><a name="exampleapp1"></a><h2 class="title">Make a simple application (Example application 1)</h2><p>You can download all files for this example application from <a href="http://karmela.fsb.hr/~bmauser/phpstartapp/examples_download/">here</a>. It is archive with two applications one simple explained step by step in this section and one little more advanced from next section. First application displays even, odd, and prim numbers. You can see demo <a href="http://karmela.fsb.hr/~bmauser/phpstartapp/">here</a>. Your applications should be written more like example application 2 from the <a href="../psa/tutorial_quick_start.pkg.html#exampleapp2">next section</a>. Application 1 is here only to show basic idea.</p>
    <span><a name="exampleapp1.intro"></a><h3 class="title">Short introduction</h3><p>You make application based on PSA by writing plugins to PSA. Plugin is just a class that extends one of the <em class = "italic">Psa_Plugin</em> classes. You can see all <em class = "italic">Psa_Plugin</em> classes in section 'plugins' of this documentation. You should put your plugin classes for this example application in directory <em>examples</em>. Location for your plugin classes can be set in <em><a href="../psa/_config.php.html">config.php</a></em> file with <em>$PSA_CFG['folders']['plugins'][]</em> option. Note that this is array so you can have more locations for your plugins. Before using plugin, PSA must be aware that there is a new plugin in some folder with plugins. That is achieved with plugin registration which is nothing more than recursive searching through folders with plugins for .php files that contains classes that extends one of the <em class = "italic">Psa_Plugin</em> class. This process can be invoked manually by calling script <a href="../psa/_register_plugins.php.html">register_plugins.php</a> in web browser, but if you set configuration option <em>$PSA_CFG['develop_mode']</em> to true, which is default when you download PSA, that will be done automatically on every request. Of course, that option in production environment should be set to false. Read comments in <em><a href="../psa/_config.php.html">config.php</a></em> file to se details and other options.</p></span>
    <span><a name="exampleapp1.router"></a><h3 class="title">Router</h3><p>Every application based on PSA must have one router plugin. Router plugin is called by <a href="../psa/_front_controller.php.html">front_controller.php</a> script so it is firstly called before all other plugins. Router plugin is used to decide which controller to call. Read more about rooter plugin <a href="../psa/plugins/Psa_Plugin_Router.html">here</a>. Note that router plugin class has to be named <em class = "italic">Router</em> and file has to be named <em class = "italic">Router.php</em> and placed in first directory with plugins (first in <em>$PSA_CFG['folders']['plugins'][]</em> configuration option in <em><a href="../psa/_config.php.html">config.php</a></em> file). That limitation exists only for router plugin.</p>
      <p>In this application we will decide which controller to call from url path. That is possible because we use rewrite rules as shown in chapter before and every request is handled by <a href="../psa/_front_controller.php.html">front_controller.php</a> script. For example, if request url is <em>http://localhost/mytestapp/web/dosomething/123/456</em> router should check if controller 'web' exists (is registered class with the name 'web' that extends <a href="../psa/plugins/Psa_Plugin_Router.html">Psa_Plugin_Router</a> class) and if not use default controller and that means that 'web' is not controller but an action to do. Later you will see what I mean by 'action'. If there was registered controller with name 'web' than action will be 'dosomething'. PSA does not do that logic for you, you have to write your router logic by yourself.</p>
      <p>Here is an example of router plugin that we will use in this test application:</p>
      <p><div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;Router&nbsp;for&nbsp;example&nbsp;applications.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">Router&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../psa/plugins/Psa_Plugin_Router.html">Psa_Plugin_Router</a><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">psa_main</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;global&nbsp;config&nbsp;array&nbsp;from&nbsp;config.php&nbsp;file</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">global&nbsp;</span><span class="src-var">$PSA_CFG</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;remove&nbsp;query&nbsp;string&nbsp;from&nbsp;url</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$request_uri_arr&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">'?'</span><span class="src-sym">,</span><span class="src-var">$_SERVER</span><span class="src-sym">[</span><span class="src-str">&quot;REQUEST_URI&quot;</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;if&nbsp;application&nbsp;web&nbsp;root&nbsp;is&nbsp;in&nbsp;some&nbsp;subfolder&nbsp;from&nbsp;server&nbsp;root&nbsp;like:&nbsp;www.example.com/my/application/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;remove&nbsp;unnecessary&nbsp;part&nbsp;of&nbsp;path.&nbsp;In&nbsp;case&nbsp;of&nbsp;url&nbsp;above&nbsp;that&nbsp;would&nbsp;be&nbsp;'/my/application'.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;This&nbsp;value&nbsp;should&nbsp;be&nbsp;set&nbsp;in&nbsp;$PSA_CFG['folders']['basedir_web']&nbsp;config&nbsp;variable&nbsp;in&nbsp;PSA&nbsp;config.php&nbsp;file</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;or&nbsp;even&nbsp;better&nbsp;in&nbsp;site&nbsp;specific&nbsp;config_override.php&nbsp;file.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$request_uri_arr</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]&nbsp;</span>=&nbsp;<a href="http://www.php.net/str_replace">str_replace</a><span class="src-sym">(</span><span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'folders'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir_web'</span><span class="src-sym">]&nbsp;</span>.&nbsp;<span class="src-str">'/'</span><span class="src-sym">,</span><span class="src-str">''</span><span class="src-sym">,</span><span class="src-var">$request_uri_arr</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;explode&nbsp;REQUEST_URI&nbsp;and&nbsp;find&nbsp;controller&nbsp;name</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$request_uri_arr&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">'/'</span><span class="src-sym">,</span><span class="src-var">$request_uri_arr</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;controller&nbsp;name&nbsp;should&nbsp;be&nbsp;the&nbsp;first&nbsp;element&nbsp;of&nbsp;the&nbsp;array</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$controller_name&nbsp;</span>=&nbsp;<span class="src-var">$request_uri_arr</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Check&nbsp;if&nbsp;controller&nbsp;with&nbsp;this&nbsp;name&nbsp;is&nbsp;registered&nbsp;and&nbsp;if&nbsp;not&nbsp;call&nbsp;'Controller_App1'&nbsp;which&nbsp;is&nbsp;our&nbsp;default&nbsp;controller.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$controller_name&nbsp;</span>==&nbsp;<span class="src-str">'app2'</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$controller_name&nbsp;</span>=&nbsp;<span class="src-str">'Controller_App2'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;start&nbsp;session</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/session_start">session_start</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;restore&nbsp;plugin&nbsp;object&nbsp;from&nbsp;session</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id"><a href="../psa/Psa_Plugin.html">Psa_Plugin</a></span><span class="src-sym">::</span><a href="../psa/Psa_Plugin.html#methodget_instance">get_instance</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">session_restore</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;remove&nbsp;controller&nbsp;name&nbsp;('app2')&nbsp;from&nbsp;$request_uri_arr</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$request_uri_arr&nbsp;</span>=&nbsp;<a href="http://www.php.net/array_slice">array_slice</a><span class="src-sym">(</span><span class="src-var">$request_uri_arr</span><span class="src-sym">,&nbsp;</span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$controller_name&nbsp;</span>=&nbsp;<span class="src-str">'Controller_App1'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Prepare&nbsp;argument&nbsp;for&nbsp;psa_run_plugins()&nbsp;method.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;We&nbsp;want&nbsp;to&nbsp;call&nbsp;psa_main()&nbsp;method&nbsp;of&nbsp;the&nbsp;controller&nbsp;and&nbsp;pass&nbsp;$request_uri_arr&nbsp;to&nbsp;the&nbsp;controller&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;cause&nbsp;the&nbsp;same&nbsp;array&nbsp;will&nbsp;be&nbsp;needed&nbsp;there&nbsp;to&nbsp;choose&nbsp;models&nbsp;and&nbsp;views</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$run_plugins</span><span class="src-sym">[</span><span class="src-var">$controller_name</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'psa_main'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$request_uri_arr</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;call&nbsp;controller.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins</a><span class="src-sym">(</span><span class="src-var">$run_plugins</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p>
      <p>This router is used for both example applications and the logic is: if controller name is '<em class = "italic">app2</em>' call controller from application 2 ('<em class = "italic">Controller_App2</em>') else call controller from application 1 ('<em class = "italic">Controller_App1</em>').</p>
      <p>Put this file into the <em>examples</em> directory. Read the comments in the file for details what does this router all do. As you can see it is a simple logic. Note that at the end is call to <a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins()</a> function that calls controller's <a href="../psa/plugins/Psa_Plugin_Controller.html#methodpsa_main">psa_main()</a> method with array as argument. In that array passed to controller are elements of url path after controller name cause they are also needed in controller to decide which action to call. For url above this array will have elements: 'web', 'dosomething', 123, 456.</p></span>
    <span><a name="exampleapp1.controller"></a><h3 class="title">Controller</h3><p>Every application based on PSA must have at least one controller plugin. Controller plugins are called from router plugin with <a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins()</a> function. This function is important in PSA since all plugins are executed only by it. Make a new folder for this application in <em>examples</em> directory and call it <em>example_app1</em>. And make file called <em>controller.php</em> in it with this content:</p>
      <p><div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;Controller&nbsp;for&nbsp;example&nbsp;application&nbsp;1.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">Controller_App1&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../psa/plugins/Psa_Plugin_Controller.html">Psa_Plugin_Controller</a><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Main&nbsp;controller&nbsp;method.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;This&nbsp;method&nbsp;is&nbsp;called&nbsp;by&nbsp;router.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">array&nbsp;</span><span class="src-doc-var">$url_args&nbsp;</span><span class="src-doc">Action&nbsp;name.&nbsp;Parts&nbsp;of&nbsp;URL&nbsp;path.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">psa_main</span><span class="src-sym">(</span><span class="src-var">$args</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;global&nbsp;config&nbsp;array</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">global&nbsp;</span><span class="src-var">$PSA_CFG</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;From&nbsp;controller&nbsp;we&nbsp;need&nbsp;to&nbsp;call&nbsp;models&nbsp;and&nbsp;views.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;First&nbsp;you&nbsp;need&nbsp;to&nbsp;decide&nbsp;which&nbsp;models&nbsp;and&nbsp;views&nbsp;to&nbsp;call.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;For&nbsp;that&nbsp;we&nbsp;will&nbsp;make&nbsp;for&nbsp;each&nbsp;request&nbsp;one&nbsp;small&nbsp;'action'&nbsp;method&nbsp;which&nbsp;will</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;return&nbsp;models&nbsp;and&nbsp;views&nbsp;for&nbsp;this&nbsp;action.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;You&nbsp;can&nbsp;make&nbsp;that&nbsp;with&nbsp;if-else&nbsp;(switch)&nbsp;statements&nbsp;if&nbsp;you&nbsp;like.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;You&nbsp;can&nbsp;put&nbsp;this&nbsp;action&nbsp;methods&nbsp;in&nbsp;separate&nbsp;file(s)&nbsp;and&nbsp;include&nbsp;it</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;here.&nbsp;It&nbsp;is&nbsp;up&nbsp;to&nbsp;you&nbsp;how&nbsp;you&nbsp;will&nbsp;do&nbsp;it,&nbsp;but&nbsp;you&nbsp;must&nbsp;somehow</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;get&nbsp;parameters&nbsp;for&nbsp;psa_run_plugins()&nbsp;function.</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;It&nbsp;is&nbsp;good&nbsp;to&nbsp;append&nbsp;some&nbsp;word&nbsp;to&nbsp;your&nbsp;acaction&nbsp;methodlike&nbsp;'_action'&nbsp;for&nbsp;security&nbsp;reasons</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;to&nbsp;be&nbsp;sure&nbsp;that&nbsp;someone&nbsp;is&nbsp;not&nbsp;able&nbsp;to&nbsp;call&nbsp;some&nbsp;built-in&nbsp;PHP&nbsp;function&nbsp;or&nbsp;some&nbsp;user&nbsp;defined</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;functions.</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;See&nbsp;also&nbsp;example&nbsp;application&nbsp;2&nbsp;where&nbsp;object&nbsp;with&nbsp;action&nbsp;methods&nbsp;is&nbsp;used&nbsp;which&nbsp;is&nbsp;much&nbsp;better</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;solution.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;This&nbsp;is&nbsp;default&nbsp;action&nbsp;(like&nbsp;index&nbsp;action).</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;This&nbsp;action&nbsp;will&nbsp;be&nbsp;called&nbsp;if&nbsp;no&nbsp;other&nbsp;action&nbsp;is&nbsp;requested.</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">default_action</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;views&nbsp;for&nbsp;this&nbsp;action.&nbsp;We&nbsp;don't&nbsp;need&nbsp;any&nbsp;model&nbsp;for&nbsp;this&nbsp;action&nbsp;in&nbsp;this&nbsp;simple&nbsp;test&nbsp;application</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'generate_html'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Action&nbsp;for&nbsp;even&nbsp;numbers</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">even_action</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;models&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'model'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'Model_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'even_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">100</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;views&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'even_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;generate_html()&nbsp;method&nbsp;of&nbsp;View_App1&nbsp;class&nbsp;will&nbsp;be&nbsp;called&nbsp;in&nbsp;every&nbsp;request&nbsp;in&nbsp;this&nbsp;application</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;so&nbsp;you&nbsp;can&nbsp;put&nbsp;this&nbsp;line&nbsp;outside&nbsp;of&nbsp;the&nbsp;action&nbsp;methods&nbsp;and&nbsp;append&nbsp;this&nbsp;element&nbsp;to</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;returning&nbsp;array&nbsp;from&nbsp;the&nbsp;action&nbsp;methods.&nbsp;I'll&nbsp;live&nbsp;it&nbsp;here&nbsp;in&nbsp;this&nbsp;example.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'generate_html'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Action&nbsp;for&nbsp;odd&nbsp;numbers</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">odd_action</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;models&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'model'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'Model_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'odd_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;views&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'odd_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'generate_html'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/**</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Action&nbsp;for&nbsp;prim&nbsp;numbers</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">prim_action</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;models&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'model'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'Model_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'prim_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span>(int)&nbsp;<span class="src-sym">@</span><span class="src-var">$_GET</span><span class="src-sym">[</span><span class="src-str">'max_prim'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;views&nbsp;for&nbsp;this&nbsp;action</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'prim_numbers'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'View_App1'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'generate_html'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;put&nbsp;some&nbsp;values&nbsp;in&nbsp;result&nbsp;object&nbsp;to&nbsp;be&nbsp;available&nbsp;in&nbsp;all&nbsp;templates</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id"><a href="../psa/Psa_Result.html">Psa_Result</a></span><span class="src-sym">::</span><a href="../psa/Psa_Result.html#methodget_instance">get_instance</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">basedir_web&nbsp;</span>=&nbsp;<span class="src-var">$PSA_CFG</span><span class="src-sym">[</span><span class="src-str">'folders'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir_web'</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;get&nbsp;action&nbsp;method&nbsp;name</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$action_function&nbsp;</span>=&nbsp;<span class="src-var">$args</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]&nbsp;</span>.&nbsp;<span class="src-str">'_action'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;check&nbsp;if&nbsp;we&nbsp;have&nbsp;defined&nbsp;this&nbsp;action&nbsp;and&nbsp;if&nbsp;not&nbsp;set&nbsp;default_action&nbsp;to&nbsp;be&nbsp;called</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/function_exists">function_exists</a><span class="src-sym">(</span><span class="src-var">$action_function</span><span class="src-sym">))</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$action_function&nbsp;</span>=&nbsp;<span class="src-str">'default_action'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;call&nbsp;action&nbsp;method&nbsp;to&nbsp;get&nbsp;parameters&nbsp;for&nbsp;psa_run_plugins()&nbsp;method</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$run_plugins&nbsp;</span>=&nbsp;<span class="src-var">$action_function</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;first&nbsp;run&nbsp;model&nbsp;plugins</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$run_plugins</span><span class="src-sym">[</span><span class="src-str">'model'</span><span class="src-sym">]</span><span class="src-sym">))</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins</a><span class="src-sym">(</span><span class="src-var">$run_plugins</span><span class="src-sym">[</span><span class="src-str">'model'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;After&nbsp;model&nbsp;plugins&nbsp;are&nbsp;called&nbsp;assign&nbsp;all&nbsp;results&nbsp;from&nbsp;models&nbsp;(every&nbsp;property&nbsp;in&nbsp;$psa_result&nbsp;object)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;to&nbsp;Smarty&nbsp;($psa_smarty)&nbsp;object.&nbsp;I&nbsp;use&nbsp;Smarty&nbsp;template&nbsp;engine&nbsp;here.</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">psa_smarty_assign_result</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;run&nbsp;view&nbsp;plugins&nbsp;at&nbsp;the&nbsp;end</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$run_plugins</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">))</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins</a><span class="src-sym">(</span><span class="src-var">$run_plugins</span><span class="src-sym">[</span><span class="src-str">'view'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p>
      <p>Read more about controller plugins <a href="../psa/plugins/Psa_Plugin_Controller.html">here</a>. Controller main purpose is to decide which models and views to call. In this example this is done with four <em>action</em> methods. Each of these methods only returns array with information which models and views to call and that array will be an argument for <a href="../psa/_scripts---functions.php.html#functionpsa_run_plugins">psa_run_plugins()</a> function. Read the comments in the example file. There will be one <em>action</em> method for every action your application does. This <em>action</em> method will tell controller which models and views to call, that means what action your application should do for a given url.</p></span>
    <span><a name="exampleapp1.model"></a><h3 class="title">Model</h3><p>All business logic of your application should be in methods in model classes that extends <a href="../psa/plugins/Psa_Plugin_Model.html">Psa_Plugin_Model</a> class. For our example application make model plugin file called <em>model.php</em> in already created folder <em>examples/example_app1</em>:</p>
      <p><div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;Model&nbsp;for&nbsp;example&nbsp;application&nbsp;1.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">Model_App1&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../psa/plugins/Psa_Plugin_Model.html">Psa_Plugin_Model</a>&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Maximum&nbsp;number&nbsp;in&nbsp;result&nbsp;used&nbsp;in&nbsp;methods&nbsp;below</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">var&nbsp;</span><span class="src-var">$max_number&nbsp;</span>=&nbsp;<span class="src-num">150</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Puts&nbsp;even&nbsp;numbers&nbsp;till&nbsp;$to_number&nbsp;in&nbsp;$psa_result&nbsp;object.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc-var">$to_number&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">even_numbers</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;get&nbsp;max&nbsp;number</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$max_number&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">get_max_number</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;find&nbsp;even&nbsp;numbers</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">for</span><span class="src-sym">(</span><span class="src-var">$i</span>=<span class="src-num">0</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i&nbsp;</span>&lt;=&nbsp;<span class="src-var">$max_number</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i</span>++<span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$i&nbsp;</span>%&nbsp;<span class="src-num">2&nbsp;</span>==&nbsp;<span class="src-num">0</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$i</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;put&nbsp;even&nbsp;numbers&nbsp;in&nbsp;psa_result&nbsp;object</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_result</span><span class="src-sym">-&gt;</span><span class="src-id">even_numbers&nbsp;</span>=&nbsp;<span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Puts&nbsp;odd&nbsp;numbers&nbsp;till&nbsp;$to_number&nbsp;in&nbsp;$psa_result&nbsp;object.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc-var">$to_number&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">odd_numbers</span><span class="src-sym">(</span><span class="src-var">$to_number&nbsp;</span>=&nbsp;<span class="src-num">120</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;get&nbsp;max&nbsp;number</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$max_number&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">get_max_number</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;find&nbsp;odd&nbsp;numbers</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">for</span><span class="src-sym">(</span><span class="src-var">$i</span>=<span class="src-num">0</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i&nbsp;</span>&lt;=&nbsp;<span class="src-var">$max_number</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i</span>++<span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$i&nbsp;</span>%&nbsp;<span class="src-num">2&nbsp;</span>==&nbsp;<span class="src-num">1</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$return</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$i</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;put&nbsp;odd&nbsp;numbers&nbsp;in&nbsp;psa_result&nbsp;object</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_result</span><span class="src-sym">-&gt;</span><span class="src-id">odd_numbers&nbsp;</span>=&nbsp;<span class="src-var">$return</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Puts&nbsp;prim&nbsp;numbers&nbsp;till&nbsp;$to_number&nbsp;in&nbsp;$psa_result&nbsp;object.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc-var">$to_number&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">prim_numbers</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;first&nbsp;prim&nbsp;number</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$prim</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;get&nbsp;max&nbsp;number</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$max_number&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">get_max_number</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;find&nbsp;prim&nbsp;numbers</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">for</span><span class="src-sym">(</span><span class="src-var">$i</span>=<span class="src-num">2</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i&nbsp;</span>&lt;=&nbsp;<span class="src-var">$max_number</span><span class="src-sym">;&nbsp;</span><span class="src-var">$i</span>++<span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$is_prim&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">for</span><span class="src-sym">(</span><span class="src-var">$j</span>=<span class="src-num">2</span><span class="src-sym">;&nbsp;</span><span class="src-var">$j</span>&lt;<span class="src-var">$i</span><span class="src-sym">;&nbsp;</span><span class="src-var">$j</span>++<span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$i</span>%<span class="src-var">$j&nbsp;</span>==&nbsp;<span class="src-num">0</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$is_prim&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$is_prim</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$prim</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$i</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;put&nbsp;prim&nbsp;numbers&nbsp;in&nbsp;psa_result&nbsp;object</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_result</span><span class="src-sym">-&gt;</span><span class="src-id">prim_numbers&nbsp;</span>=&nbsp;<span class="src-var">$prim</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Returns&nbsp;$this-&gt;max_number&nbsp;if&nbsp;$to_number&nbsp;is&nbsp;larger&nbsp;than&nbsp;$this-&gt;max_number.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;This&nbsp;is&nbsp;helper&nbsp;method&nbsp;for&nbsp;methods&nbsp;above.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">int&nbsp;</span><span class="src-doc-var">$to_number&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@return&nbsp;</span><span class="src-doc-type">int&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">get_max_number</span><span class="src-sym">(</span><span class="src-var">$to_number</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$to_number&nbsp;</span>&gt;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">max_number</span><span class="src-sym">)</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">max_number</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$to_number</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p>
      <p>Read more about model plugins <a href="../psa/plugins/Psa_Plugin_Model.html">here</a>. As you can see there is one model method for each action this simple application does (even_numbers, odd_numbers, prim_numbers). That will not be true for more complex application where you can call more model methods from various model classes in one controller action. Note that these methods do not return values, they just put results in <a href="../psa/Psa_Result.html">Psa_Result</a> object. Model methods can also return values if you need that. It is important that after executing model methods for some action all needed results are in <a href="../psa/Psa_Result.html">Psa_Result</a> object. For example after executing even_numbers() method, even numbers that we want are in <em class = "italic">even_numbers</em> propery (array) of the <a href="../psa/Psa_Result.html">Psa_Result</a> object.</p></span>
    <span><a name="exampleapp1.view"></a><h3 class="title">View</h3><p>View plugins are similar to model plugins, but in view plugin methods should be only logic that is needed for displaying results, in this example application, html pages. We will use <a href="http://www.smarty.net/">Smarty</a> template engine to generate html pages. I have included <a href="http://www.smarty.net/">Smarty</a> template engine with PSA and one simple class <a href="../psa/Psa_Dully.html">Psa_Dully</a> that is very simple template engine that you can use instead of Smarty. There are two important methods of controller class if you use one of these template engines <a href="../psa/plugins/Psa_Plugin_Controller.html#methodpsa_smarty_assign_result">psa_smarty_assign_result()</a> and Psa_Plugin_Controller::psa_dully_assign_result(). For this example application make view plugin file called <em>view.php</em> in already created folder <em>examples/example_app1</em>:</p><p><div class="src-code"><ol><li><div class="src-line"><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*&nbsp;View&nbsp;for&nbsp;example&nbsp;application&nbsp;1.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">View_App1&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../psa/plugins/Psa_Plugin_View.html">Psa_Plugin_View</a><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Renders&nbsp;even_numbers.tpl&nbsp;template&nbsp;and&nbsp;puts&nbsp;rendered&nbsp;html&nbsp;in&nbsp;&quot;result&quot;&nbsp;smarty&nbsp;value</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/&nbsp;&nbsp;&nbsp;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">even_numbers</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rendered_result&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/even_numbers.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">assign</span><span class="src-sym">(</span><span class="src-str">&quot;result&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$rendered_result</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Renders&nbsp;odd_numbers.tpl&nbsp;template&nbsp;and&nbsp;puts&nbsp;rendered&nbsp;html&nbsp;in&nbsp;&quot;result&quot;&nbsp;smarty&nbsp;value</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">odd_numbers</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rendered_result&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/odd_numbers.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">assign</span><span class="src-sym">(</span><span class="src-str">&quot;result&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$rendered_result</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}&nbsp;&nbsp;&nbsp;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Renders&nbsp;prim_numbers.tpl&nbsp;template&nbsp;and&nbsp;puts&nbsp;rendered&nbsp;html&nbsp;in&nbsp;&quot;result&quot;&nbsp;smarty&nbsp;value</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">prim_numbers</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rendered_result&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/prim_numbers.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">assign</span><span class="src-sym">(</span><span class="src-str">&quot;result&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$rendered_result</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Main&nbsp;template&nbsp;render&nbsp;and&nbsp;display&nbsp;method.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Every&nbsp;application&nbsp;should&nbsp;have&nbsp;one&nbsp;method&nbsp;like&nbsp;this&nbsp;for&nbsp;one&nbsp;controller.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;This&nbsp;method&nbsp;can&nbsp;be&nbsp;written&nbsp;to&nbsp;determine&nbsp;if&nbsp;request&nbsp;is&nbsp;made&nbsp;by&nbsp;ajax&nbsp;or&nbsp;not&nbsp;and&nbsp;echo&nbsp;only</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;ajax&nbsp;result&nbsp;or&nbsp;whole&nbsp;html&nbsp;page.</span></div></li>
<li><div class="src-line"><span class="src-doc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">function&nbsp;</span><span class="src-id">generate_html</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rendered_menu&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/menu.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rendered_header&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/header.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">assign</span><span class="src-sym">(</span><span class="src-str">&quot;header&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$rendered_header</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">assign</span><span class="src-sym">(</span><span class="src-str">&quot;menu&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$rendered_menu</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">psa_smarty</span><span class="src-sym">-&gt;</span><span class="src-id">fetch</span><span class="src-sym">(</span><span class="src-str">&quot;example_app1/main.tpl&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-php">?&gt;</span></div></li>
</ol></div></p>Read more about view plugins <a href="../psa/plugins/Psa_Plugin_View.html">here</a>. There is one view method (even_numbers, odd_numbers, prim_numbers) for each action. Each view method calls <a href="http://www.smarty.net/">Smarty</a> methods to render HTML code from template files and generate_html() method that is called in every action. This method actually displays html page. It takes html rendered from other view methods and compounds whole html page and displays it. All template files should be placed in <em>templates/</em> directory. For this example application create folder <em>templates/example_app1</em> and put template files in it. Here are Smarty templates used with this application:<p>template file <em>even_numbers.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">strong</span>&gt;<span class="src-id">Even&nbsp;numbers</span>:&lt;/<span class="src-id">strong</span>&gt;&lt;<span class="src-id">br&nbsp;</span>/&gt;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-key">foreach&nbsp;</span><span class="src-id">from</span>=<span class="src-var">$even_numbers&nbsp;</span><span class="src-id">item</span>=<span class="src-id">result_item&nbsp;name</span>=<span class="src-id">result_name</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&lt;<span class="src-id">span&nbsp;style</span>=<span class="src-str">&quot;</span><span class="src-str">font-size:&nbsp;{<span class="src-var">$smarty</span>.<span class="src-key">foreach</span>.<span class="src-id">result_name</span>.<span class="src-id">iteration</span><span class="src-sym">}</span>px</span><span class="src-str">&quot;</span>&gt;<span class="src-sym">{</span><span class="src-var">$result_item</span><span class="src-sym">}</span>&lt;/<span class="src-id">span</span>&gt;</div></li>
<li><div class="src-line"><span class="src-sym">{</span>/<span class="src-key">foreach</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&lt;/<span class="src-id">div</span>&gt;</div></li>
</ol></div></p><p>template file <em>odd_numbers.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">strong</span>&gt;<span class="src-id">Odd&nbsp;numbers</span>:&lt;/<span class="src-id">strong</span>&gt;&lt;<span class="src-id">br&nbsp;</span>/&gt;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-key">foreach&nbsp;</span><span class="src-id">from</span>=<span class="src-var">$odd_numbers&nbsp;</span><span class="src-id">item</span>=<span class="src-id">result_item</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">{</span><span class="src-var">$result_item</span><span class="src-sym">}</span><span class="src-sym">,&nbsp;</span></div></li>
<li><div class="src-line"><span class="src-sym">{</span>/<span class="src-key">foreach</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&nbsp;</div></li>
<li><div class="src-line">&lt;/<span class="src-id">div</span>&gt;</div></li>
</ol></div></p><p>template file <em>prim_numbers.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">strong</span>&gt;<span class="src-id">Prim&nbsp;numbers</span>:&lt;/<span class="src-id">strong</span>&gt;&lt;<span class="src-id">br&nbsp;</span>/&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">ul</span>&gt;</div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-key">foreach&nbsp;</span><span class="src-id">from</span>=<span class="src-var">$prim_numbers&nbsp;</span><span class="src-id">item</span>=<span class="src-id">result_item</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&lt;<span class="src-id">li</span>&gt;<span class="src-sym">{</span><span class="src-var">$result_item</span><span class="src-sym">}</span>&lt;/<span class="src-id">li</span>&gt;</div></li>
<li><div class="src-line"><span class="src-sym">{</span>/<span class="src-key">foreach</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&lt;/<span class="src-id">ul</span>&gt;</div></li>
</ol></div></p><p>template file <em>header.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;&lt;<span class="src-id">h1</span>&gt;<span class="src-id">Example&nbsp;application&nbsp;</span><span class="src-num">1</span>&lt;/<span class="src-id">h1</span>&gt;</div></li>
<li><div class="src-line">&lt;/<span class="src-id">div</span>&gt;</div></li>
</ol></div></p><p>template file <em>menu.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&nbsp;&nbsp;<span class="src-id">Menu</span>:&nbsp;&lt;<span class="src-id">a&nbsp;href</span>=<span class="src-str">&quot;</span>{<span class="src-var">$basedir_web<span class="src-str"></span><span class="src-sym">}</span>/even/</span><span class="src-str">&quot;</span>&gt;<span class="src-id">even&nbsp;numbers</span>&lt;/<span class="src-id">a</span>&gt;&nbsp;|&nbsp;&lt;<span class="src-id">a&nbsp;href</span>=<span class="src-str">&quot;</span>{<span class="src-var">$basedir_web<span class="src-str"></span><span class="src-sym">}</span>/odd/</span><span class="src-str">&quot;</span>&gt;<span class="src-id">odd&nbsp;numbers</span>&lt;/<span class="src-id">a</span>&gt;&nbsp;|&nbsp;&lt;<span class="src-id">a&nbsp;href</span>=<span class="src-str">&quot;</span>{<span class="src-var">$basedir_web<span class="src-str"></span><span class="src-sym">}</span>/prim/?max_prim=100</span><span class="src-str">&quot;</span>&gt;<span class="src-id">prim&nbsp;numbers</span>&lt;/<span class="src-id">a</span>&gt;</div></li>
<li><div class="src-line">&lt;/<span class="src-id">div</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">hr&nbsp;</span>/&gt;</div></li>
</ol></div></p><p>template file <em>main.tpl</em>:</p><p><div class="src-code"><ol><li><div class="src-line">&lt;<span class="src-sym">!</span><span class="src-id">DOCTYPE&nbsp;html&nbsp;</span><span class="src-key">PUBLIC&nbsp;</span><span class="src-str">&quot;-//W3C//DTD&nbsp;XHTML&nbsp;1.0&nbsp;Transitional//EN&quot;&nbsp;&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">html&nbsp;xmlns</span>=<span class="src-str">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">head</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">meta&nbsp;http</span>-<span class="src-id">equiv</span>=<span class="src-str">&quot;Content-Type&quot;&nbsp;</span><span class="src-id">content</span>=<span class="src-str">&quot;text/html;&nbsp;charset=utf-8&quot;&nbsp;</span>/&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">title</span>&gt;<span class="src-id">Test&nbsp;app&nbsp;</span><span class="src-num">1</span>&lt;/<span class="src-id">title</span>&gt;</div></li>
<li><div class="src-line">&lt;/<span class="src-id">head</span>&gt;</div></li>
<li><div class="src-line">&lt;<span class="src-id">body</span>&gt;</div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-var">$header</span><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-var">$menu</span><span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">{</span><span class="src-var">$result</span><span class="src-sym">}</span></div></li>
<li><div class="src-line">&lt;/<span class="src-id">body</span>&gt;</div></li>
<li><div class="src-line">&lt;/<span class="src-id">html</span>&gt;</div></li>
</ol></div></p></span></span><span><a name="exampleapp2"></a><h2 class="title">Not so simple application (Example application 2)</h2><p>This is application with AJAX and <a href="http://www.flickr.com">Flickr</a> search which uses <a href="http://framework.zend.com">Zend Framework</a>. You can see demo <a href="http://karmela.fsb.hr/~bmauser/phpstartapp/app2">here</a> and dowload it from <a href="http://karmela.fsb.hr/~bmauser/phpstartapp/examples_download/">here</a>. This archive also includes simple application explained in section above. After reading <a href="../psa/tutorial_quick_start.pkg.html#exampleapp1">section before</a> with example application 1 you should understand everything in this application by reading comments in files.</p></span></div>

	<table class="tutorial-nav-box">
	<tr>
		<td style="width: 30%">
							<a href="../psa/tutorial_psa_quick_start.pkg.html"><img src="../media/images/previous_button.png" alt="Previous"></a>
					</td>
		<td style="text-align: center">
					</td>
		<td style="text-align: right; width: 30%">
							<span class="disabled"><img src="../media/images/next_button_disabled.png" alt="Next"></span>
					</td>
	</tr>
	<tr>
		<td style="width: 30%">
							<span class="detail">Quick Start</span>
					</td>
		<td style="text-align: center">
					</td>
		<td style="text-align: right; width: 30%">
					</td>
	</tr>
</table>
	
	<p class="notes" id="credit">
		Documentation generated on Mon, 06 Apr 2009 23:49:52 +0200 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.2</a>
	</p>
	</div></body>
</html>